package org.dromara.learning_xq.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.dromara.learning_xq.entity.AsClassManagement;
import org.dromara.learning_xq.service.AsClassManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/AsClassManagement")
@Tag(name = "班级管理")
public class AsClassManagementController {

    @Autowired
    private AsClassManagementService asClassManagementService;


    /**
     * 批量添加班级管理数据
     *
     * @param asClassManagement 班级管理数据列表
     * @return 添加操作的结果
     */
    @PostMapping("/increaseAsClassManagement")
    @Operation(summary = "添加班级")
    public ResponseEntity<Map<String, Object>> increaseAsClassManagement(@RequestBody List<AsClassManagement> asClassManagement) {
        // 调用服务层方法批量添加数据
        boolean result = asClassManagementService.increaseAsClassManagement(asClassManagement);

        // 构建响应实体，包含添加结果和状态信息
        Map<String, Object> response = new HashMap<>();
        response.put("success", result);

        // 根据添加结果返回相应的HTTP状态码和响应实体
        return result ? ResponseEntity.status(HttpStatus.CREATED).body(response) : ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
    }

    @PostMapping("/selectAsClassManagement")
    @Operation(summary = "查询班级")
    public ResponseEntity<Map<String, Object>> selectAsClassManagement( AsClassManagement asClassManagement) {
        Map<String, Object> response = new HashMap<>();

        try {
            List<AsClassManagement> classManagementList = asClassManagementService.selectAsClassManagement(asClassManagement);

            if (classManagementList != null && !classManagementList.isEmpty()) {
                response.put("success", true);
                response.put("data", classManagementList);
                response.put("message", "查询成功");
                return ResponseEntity.ok(response);
            } else {
                response.put("success", false);
                response.put("message", "没有找到相关数据");
                return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response);
            }
        } catch (Exception e) {
            response.put("success", false);
            response.put("message", "查询失败: " + e.getMessage());
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
        }
    }


}
